<script setup lang="ts">
import { useUserStore } from '@/stores/user';
import { ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router';

const handCommand = (command: string)=>{
  if(command==='logout'){
    logout()
  }
}
// 退出登录
const store = useUserStore()
const router = useRouter()
const logout = async () => {
  // 弹框确认
  const res = await ElMessageBox.confirm(
    '您确定要退出登录吗？', 
    '提示', 
    {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }
)
  if(res === 'confirm'){
    store.setToken('')
    router.replace('/login')
  }

}
</script>

<template>
  <div class="nav-bar">
    <!-- breadcrumb -->
    <div></div>
    <!-- dropdown -->
    <el-dropdown @command="handCommand">
      <div class="user-wrapper">黑马管理员</div>
      <template #dropdown>
        <el-dropdown-menu >
          <el-dropdown-item>首页</el-dropdown-item>
          <el-dropdown-item>项目地址</el-dropdown-item>
          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<style lang="scss" scoped>
.nav-bar {
  height: 60px;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;

  .user-wrapper {
    outline: none;
    cursor: default;
    color: var(--el-color-black);
  }
}
</style>
